package com.visikard.asynctask;

import android.os.Handler;
import android.os.Message;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.GetCouponDetailResponse;

public class GetDetailCouponTask extends BaseTask {

	public static final int POS_UID = 0;
	public static final int POS_COUPON_ID = 1;

	public GetDetailCouponTask(Handler handler) {
		super(handler);
	}

	public GetDetailCouponTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		long uid = (Long) params[POS_UID];
		int couponID = (Integer) params[POS_COUPON_ID];

		CouponBUS busObj = new CouponBUS();
		return busObj.getCouponDetail(uid, couponID);
	}

	@Override
	protected boolean handleResult(Object result) {
		GetCouponDetailResponse response = (GetCouponDetailResponse) result;
		if (result != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					Message successMsg = new Message();
					successMsg.what = UIMessage.MSG_GET_COUPON_DETAIL_FINISH;
					successMsg.obj = response.getItemCouponBuilderCreate();
					mUIHandler.sendMessage(successMsg);
					return true;
			}
		}
		return false;
	}

}
